﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Forget.HRBLL.Logical;

namespace HRWebSite.Employee
{
    public partial class CreateEmployee : BasePage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            this.HRLimits = Limits.EmployeeManage;
            this.HRLimitAttribute = Forget.HRBLL.LimitAttribute.Read | Forget.HRBLL.LimitAttribute.Add;
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                if (!string.IsNullOrEmpty(this.Request["NumID"]))
                    this.NumberID.Text = this.Request["NumID"];
                else
                    this.Response.Write("<script>alert('传入参数有误，请重试或与管理员联系！');</script>");
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            DateTime m_birthday = new DateTime(int.Parse(this.Year1.SelectedValue), int.Parse(this.Month1.SelectedValue), int.Parse(this.Day1.SelectedValue));
            DateTime m_intim = new DateTime(int.Parse(this.Year2.SelectedValue), int.Parse(this.Month2.SelectedValue), int.Parse(this.Day2.SelectedValue));
            float m_height = string.IsNullOrEmpty(this.Height.Text) ? 0 : long.Parse(this.Height.Text);
            float m_weight = string.IsNullOrEmpty(this.Weight.Text) ? 0 : long.Parse(this.Weight.Text);
            int m_eptype = int.Parse(this.EpType.SelectedValue);
            int m_positionnum = int.Parse(this.DropDownList8.SelectedValue);
            bool sex = this.Sex.SelectedValue == "0" ? true : false;
            bool marry = this.Marry.SelectedValue == "1" ? false : true;
            int depart = 0;
            int.TryParse(this.Request.Params["departID"], out depart);
            if (EmployeeLogical.AddEmployeeInfo(this.NumberID.Text, sex, m_birthday, m_height, m_weight, this.Party.Text,
                this.Place.Text, m_intim, m_eptype, this.IDCard.Text, this.Address.Text, this.Education.Text,
                this.Professional.Text, this.Nation.Text, m_positionnum, marry, this.University.Text, depart))
                Response.Write("<script>alert('添加成功');</script>");
            else
                Response.Write("<script>alert('添加失败');</script>");
        }
    }
}